package com.liu.demo4.service;

import com.liu.demo4.entity.User;
import com.liu.demo4.dao.UserDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginService {
    private static final Logger log = LoggerFactory.getLogger(LoginService.class);

    @Autowired
    private UserDao userDao;

    public boolean login(String username, String password) {
        log.info("尝试登录: 用户名={}, 密码={}", username, password);
        User user = userDao.getUserByName(username, password);
        if (user != null && user.getPassword().equals(password)) {
            log.info("登录成功: 用户名={}", username);
            return true;
        } else {
            log.warn("登录失败: 用户名={}, 密码={}", username, password);
            return false;
        }
    }
}
